<template>
  <div class="qualiy_add">
    <el-dialog
      title="添加周边收敛量测数据"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" class="demo-form-inline" :model="form" label-width="120px">
        <!-- 必填 -->
        <el-form-item label="断面">
          <el-select style="width:100%" v-model="form.sId" placeholder="请选择断面">
            <el-option v-for="v in TunnelSection" :label="v.sectionName" :key="v.id" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
        <!-- 必填 -->
        <el-form-item label="测量时间">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
            v-model="form.createTime"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <!-- 必填 -->
        <el-form-item label="SL1-SL2测量值">
          <el-input v-model="form.peripheryValue"></el-input>
        </el-form-item>
        <el-form-item label="SL3-SL4测量值">
          <el-input v-model="form.periphery2Value"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="create">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
  
  <script>
import api from '../../../api'
import qs from 'qs'

export default {
  data() {
    return {
      dialogVisible: false,
      etype: [],
      tunnelList: [],
      TunnelSection: [],
      form: {
        wId: '', //洞幅id
        sId: '', //断面id
        createTime: '', //测量时间
        periphery2Value: '',
        peripheryValue: '' //备注
      }
    }
  },
  mounted() {
    this.$bus.$on('onAddmonitorPeripheryshow', (flag) => {
      if (this.form.wId == '') {
        this.$message({
          type: 'fail',
          message: '请选择洞幅'
        })
        this.dialogVisible = false
      } else {
        this.dialogVisible = flag
      }
    })
    this.$bus.$on('onAddmonitorPeripheryfoWid', (flag) => {
      this.form.wId = flag
      this.findByTunnelSection(this.form.wId)
    })
  },
  methods: {
    // 查询断面
    findByTunnelSection(wid) {
      api
        .tunnelSectionfindByWid({ wid })
        .then((res) => {
          if (res.data.code == 2001) {
            console.log(res.data)
            this.TunnelSection = res.data.data
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    create() {
      if (this.form.wId == '') {
        this.$message({
          type: 'fail',
          message: '请选择洞幅'
        })
        return
      }
      if (this.form.sId == '') {
        this.$message({
          type: 'fail',
          message: '请选择断面'
        })
        return
      }
      api
        .monitorPeripherysave(qs.stringify(this.form))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
            this.dialogVisible = false
            this.$bus.$emit('onRefreshmonitorPeriphery', this.form.wId)
          } else {
            this.$message({
              type: 'fail',
              message: res.data.message
            })
          }
        })
        .catch((err) => {})
    },

    onSubmit() {
      console.log('submit!')
    },
    handleCommand(command) {
      alert(command)
    },
    funsection() {}
  }
}
</script>
  
<style scoped>
.qualiy_add {
  width: 1000px;
  margin: 10px;
}
.el-dialog {
  width: 40%;
}
</style>